/**
 * tigerrad
 * fall 2006
 */

#ifndef _FRAMEBUFFER_H
#define _FRAMEBUFFER_H

#include "Util.h"
#include "Texture.h"
#include "Renderbuffer.h"

/**
 * Abstracts a Framebuffer Object.
 */
class Framebuffer
{
	public:
		/**
		 * Constructor.
		 * @param name Debug name(id)
		 */
		Framebuffer(const std::string& name) :
			_name(name) 
		{
			glGenFramebuffersEXT(1, &_glName);
			std::cerr << _glName << std::endl;
		}
	
		/**
		 * Return the debug name.
		 */
		std::string getName() const { return _name; }

		/**
		 * Attach a Texture to this Framebuffer.
		 * Will verify completeness.
		 */
		void attachTexture(const TexturePtr& t, GLenum where);

		/**
		 * Attach a RenderBuffer to this Framebuffer.
		 * Will verify completeness.
		 */
		void attachRenderbuffer(const RenderbufferPtr& t);

		/**
		 * Bind the Framebuffer and save the current
		 * draw buffer.
		 */
		void bind();

		/**
		 * Unbind the Framebuffer and restore the saved
		 * draw buffer.
		 */
		void unbind();

		/**
		 * Set the draw buffer.
		 */
		void drawBuffer(GLenum buf);

		/**
		 * Will set the first num color attachments as the draw buffers.
		 */
		void drawColorAttachments(GLuint num);

		/**
		 * Destructor.
		 */
		Framebuffer() 
		{
			// TODO cleanup
		}
		
	private:
		std::string _name;
		GLuint _glName;
//		std::vector<TexturePtr> _textures;
//		std::vector<RenderbufferPtr> _renderbuffers;
		GLint _savedDrawBuffer;


		static GLenum _buffers[];
};

typedef boost::shared_ptr<Framebuffer> FramebufferPtr;

#endif

